package com.struts.web.corpor.register;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

import com.base.Constants;
import com.ibatis.po.corpor.TCorporation;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.lg.system.CLGAction;
import com.lg.system.CSqlMap;
import com.struts.deal.corpor.register.Deal;

public class CorporBaseAction extends CLGAction {
     
	
	
	public ActionForward execute(ActionMapping actionMapping,
            ActionForm actionForm,
            HttpServletRequest request,
            HttpServletResponse response) throws
Exception {
		boolean result = false;
		CorporBaseForm aWebForm = (CorporBaseForm)actionForm;
		TCorporation corpor  = new TCorporation();
		SqlMapClient sqlmap=CSqlMap.getSqlMapConfig();
		ActionMessages msgs = new ActionMessages();
		corpor.setLoginName(aWebForm.getLoginName().trim());
		
			int count = 0;
			count = ((Integer)sqlmap.queryForObject("T_CORPORATION.selectCount",corpor)).intValue();
			if(count>0){
				msgs.add("commonMsgs",new ActionMessage(Constants.USER_EXIST));
				saveErrors(request,msgs);
				return actionMapping.findForward("fail");
			}else{
				result=Deal.addBase(request, response, aWebForm);
				if(result==true){
					return actionMapping.findForward("corpordetail");
				}else{
					msgs.add("commonMsgs",new ActionMessage(Constants.ADDMER_FAIL_KEY));
					saveErrors(request,msgs);
				    return actionMapping.findForward("fail");
				}
			}
		
}
	
	
}
